using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Domain.Effectivity
{
    /// <summary>
    /// Specifications for trying to get an effectivity of a temporal object.
    /// </summary>
    [TestClass]
    public class WhenTryGettingSnapshotFromTemporal : TemporalUnitTest
    {
        /// <summary>
        /// Should return true and pass when there is an effectivity on the given date.
        /// </summary>
        [TestMethod]
        public void ShouldReturnTrueWhenEffectivityExists()
        {
            ITemporal<string> effectivityManager = Create();
            DateTime validityDate = new DateTime(2000, 1, 15);

            IEffectivity<string> actualEffectivity;
            Assert.IsTrue(effectivityManager.TryGetSnapshot(validityDate, out actualEffectivity));
            Assert.AreEqual(InitialTemporalValue, actualEffectivity.Element);
        }

        /// <summary>
        /// Should return false and default value when there is no effectivity on the given date.
        /// </summary>
        [TestMethod]
        public void ShouldReturnFalseWhenEffectivityDoesNotExist()
        {
            ITemporal<string> effectivityManager = Create();
            DateTime validityDate = new DateTime(1999, 1, 15);

            IEffectivity<string> actualEffectivity;
            Assert.IsFalse(effectivityManager.TryGetSnapshot(validityDate, out actualEffectivity));
            Assert.IsNull(actualEffectivity);
        }
    }
}